package com.esri.core.renderer;

import com.esri.core.geometry.Geometry;
import com.esri.core.internal.util.d;
import com.esri.core.map.Feature;
import com.esri.core.map.FeatureTemplate;
import com.esri.core.map.FeatureType;
import com.esri.core.map.Field;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.Symbol;
import com.esri.core.symbol.SymbolHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonNode;

/* loaded from: classes.dex */
public class UniqueValueRenderer extends BaseRenderer {
    public static final String TYPE = "uniqueValue";
    private static final String k = ",";
    private static final long serialVersionUID = 1;
    String d;
    String e;
    String f;
    String g;
    Symbol h;
    String i;
    List<UniqueValue> j;

    @Override // com.esri.core.renderer.BaseRenderer
    protected String getType() {
        return TYPE;
    }

    public UniqueValueRenderer() {
        this.d = null;
        this.e = null;
        this.f = null;
        this.g = null;
        this.j = new ArrayList();
    }

    public UniqueValueRenderer(JsonNode jsonNode) throws Exception {
        super(jsonNode);
        String str = null;
        this.d = null;
        this.e = null;
        this.f = null;
        this.g = null;
        this.j = new ArrayList();
        if (jsonNode == null) {
            return;
        }
        JsonNode jsonNode2 = jsonNode.get("field1");
        if (jsonNode2 != null && !jsonNode2.isNull()) {
            String textValue = jsonNode2.getTextValue();
            this.d = textValue;
            this.d = (textValue == null || textValue.trim().length() == 0) ? null : this.d;
        }
        JsonNode jsonNode3 = jsonNode.get("field2");
        if (jsonNode3 != null && !jsonNode3.isNull()) {
            String textValue2 = jsonNode3.getTextValue();
            this.e = textValue2;
            this.e = (textValue2 == null || textValue2.trim().length() == 0) ? null : this.e;
        }
        JsonNode jsonNode4 = jsonNode.get("field3");
        if (jsonNode4 != null && !jsonNode4.isNull()) {
            String textValue3 = jsonNode4.getTextValue();
            this.f = textValue3;
            this.f = (textValue3 == null || textValue3.trim().length() == 0) ? null : this.f;
        }
        JsonNode jsonNode5 = jsonNode.get("fieldDelimiter");
        if (jsonNode5 != null && !jsonNode5.isNull()) {
            String textValue4 = jsonNode5.getTextValue();
            this.g = textValue4;
            if (textValue4 != null && textValue4.length() != 0) {
                str = this.g;
            }
            this.g = str;
        }
        JsonNode jsonNode6 = jsonNode.get("defaultSymbol");
        if (jsonNode6 != null && !jsonNode6.isNull()) {
            this.h = SymbolHelper.parseSymbol(jsonNode6);
        }
        JsonNode jsonNode7 = jsonNode.get("defaultLabel");
        if (jsonNode7 != null && !jsonNode7.isNull()) {
            this.i = jsonNode7.getTextValue();
        }
        String str2 = this.g;
        str2 = (str2 == null || str2.equals("")) ? k : str2;
        JsonNode jsonNode8 = jsonNode.get("uniqueValueInfos");
        if (jsonNode8 == null || jsonNode8.isNull() || !jsonNode8.isArray()) {
            return;
        }
        Iterator<JsonNode> it = jsonNode8.iterator();
        while (it.hasNext()) {
            UniqueValue uniqueValue = new UniqueValue(it.next());
            if (uniqueValue.a != null && uniqueValue.a.length > 0) {
                if (this.e != null || this.f != null) {
                    uniqueValue.setValue(uniqueValue.a[0].toString().split(str2));
                }
                this.j.add(uniqueValue);
            }
        }
    }

    public String getField1() {
        return this.d;
    }

    public void setField1(String str) {
        this.d = str;
    }

    public String getField2() {
        return this.e;
    }

    public void setField2(String str) {
        this.e = str;
    }

    public String getField3() {
        return this.f;
    }

    public void setField3(String str) {
        this.f = str;
    }

    public String getFieldDelimiter() {
        return this.g;
    }

    public void setFieldDelimiter(String str) {
        this.g = str;
    }

    public Symbol getDefaultSymbol() {
        return this.h;
    }

    public void setDefaultSymbol(Symbol symbol) {
        this.h = symbol;
    }

    public String getDefaultLabel() {
        return this.i;
    }

    public void setDefaultLabel(String str) {
        this.i = str;
    }

    public List<UniqueValue> getUniqueValueInfos() {
        return this.j;
    }

    public void setUniqueValueInfos(List<UniqueValue> list) {
        this.j = list;
    }

    public boolean addUniqueValue(UniqueValue uniqueValue) {
        if (uniqueValue != null) {
            return this.j.add(uniqueValue);
        }
        return false;
    }

    public boolean removeUniqueValue(UniqueValue uniqueValue) {
        if (uniqueValue != null) {
            return this.j.remove(uniqueValue);
        }
        return false;
    }

    @Deprecated
    public Symbol getSymbol(Graphic graphic) {
        return getSymbol((Feature) graphic);
    }

    @Override // com.esri.core.renderer.Renderer
    public Symbol getSymbol(Feature feature) {
        char c = this.e == null ? (char) 1 : this.f == null ? (char) 2 : (char) 3;
        Object attributeValue = feature.getAttributeValue(this.d);
        Object attributeValue2 = c > 1 ? feature.getAttributeValue(this.e) : null;
        Object attributeValue3 = c == 3 ? feature.getAttributeValue(this.f) : null;
        if ((this.d != null && attributeValue == null) || ((c > 1 && attributeValue2 == null) || (c == 3 && attributeValue3 == null))) {
            return this.h;
        }
        for (UniqueValue uniqueValue : this.j) {
            if (uniqueValue.a != null && uniqueValue.a.length != 0) {
                boolean a = a(uniqueValue.a[0], attributeValue);
                if (c > 1 && a) {
                    if (uniqueValue.a.length < 2) {
                        continue;
                    } else {
                        a = a(uniqueValue.a[1], attributeValue2);
                        if (c == 3 && a) {
                            if (uniqueValue.a.length < 3) {
                                continue;
                            } else {
                                a = a(uniqueValue.a[2], attributeValue3);
                            }
                        }
                    }
                }
                if (a) {
                    return uniqueValue.d;
                }
            }
        }
        return this.h;
    }

    public FeatureType[] toTypes(Field[] fieldArr, Geometry.Type type) {
        Object[] value;
        Object obj;
        int i;
        Object valueOf;
        String str = this.e;
        int i2 = 3;
        int i3 = 1;
        int i4 = str == null ? 1 : this.f == null ? 2 : 3;
        int[] iArr = {-1, -1, -1};
        String[] strArr = {this.d, str, this.f};
        FeatureTemplate.DRAWING_TOOL b = d.b(type);
        if (fieldArr != null && fieldArr.length > 0) {
            int i5 = 0;
            for (Field field : fieldArr) {
                if (this.d != null && field.getName().equalsIgnoreCase(this.d)) {
                    iArr[0] = field.getFieldType();
                    i5++;
                }
                if (this.e != null && field.getName().equalsIgnoreCase(this.e)) {
                    iArr[1] = field.getFieldType();
                    i5++;
                }
                if (this.f != null && field.getName().equalsIgnoreCase(this.f)) {
                    iArr[2] = field.getFieldType();
                    i5++;
                }
                if (i5 == i4) {
                    break;
                }
            }
        }
        ArrayList arrayList = new ArrayList();
        List<UniqueValue> list = this.j;
        if (list != null) {
            int i6 = 0;
            for (UniqueValue uniqueValue : list) {
                if (uniqueValue != null && (value = uniqueValue.getValue()) != null && value.length == i4) {
                    LinkedHashMap linkedHashMap = new LinkedHashMap(i2);
                    for (int i7 = 0; i7 < i4; i7++) {
                        if (strArr[i7] != null && strArr[i7].trim().length() != 0 && (obj = value[i7]) != null) {
                            try {
                                i = iArr[i7];
                            } catch (NumberFormatException unused) {
                            }
                            if (i != 10 && i != 20) {
                                if (i == 30 || i == 40) {
                                    valueOf = Double.valueOf((String) obj);
                                } else if (i == 50) {
                                    valueOf = Long.valueOf((String) obj);
                                } else if (i != 80) {
                                    linkedHashMap.put(strArr[i7], obj);
                                }
                                obj = valueOf;
                                linkedHashMap.put(strArr[i7], obj);
                            }
                            valueOf = Integer.valueOf((String) obj);
                            obj = valueOf;
                            linkedHashMap.put(strArr[i7], obj);
                        }
                    }
                    String str2 = uniqueValue.b == null ? "" : uniqueValue.b;
                    String str3 = uniqueValue.c != null ? uniqueValue.c : "";
                    int i8 = i6 + 1;
                    String valueOf2 = String.valueOf(i6);
                    FeatureTemplate[] featureTemplateArr = new FeatureTemplate[i3];
                    featureTemplateArr[0] = new FeatureTemplate(str2, str3, linkedHashMap, b);
                    arrayList.add(new FeatureType(valueOf2, (String) null, Arrays.asList(featureTemplateArr)));
                    i6 = i8;
                }
                i2 = 3;
                i3 = 1;
            }
        }
        return (FeatureType[]) arrayList.toArray(new FeatureType[0]);
    }

    private boolean a(Object obj, Object obj2) {
        if (obj == null || obj2 == null) {
            return obj == obj2;
        }
        try {
            if (obj2 instanceof Integer) {
                if (Integer.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj2 instanceof Float) {
                if (Float.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj2 instanceof Long) {
                if (Long.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj2 instanceof Short) {
                if (Short.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj2 instanceof Double) {
                if (Double.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj2 instanceof Boolean) {
                if (Boolean.valueOf(obj.toString()).equals(obj2)) {
                    return true;
                }
            } else if (obj.equals(obj2)) {
                return true;
            }
            return false;
        } catch (Exception unused) {
            return obj.toString().equals(obj2.toString());
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.core.renderer.BaseRenderer
    public void toJson(JsonGenerator jsonGenerator) throws Exception {
        super.toJson(jsonGenerator);
        String str = this.d;
        if (str != null) {
            jsonGenerator.writeStringField("field1", str);
        }
        String str2 = this.e;
        if (str2 != null) {
            jsonGenerator.writeStringField("field2", str2);
        }
        String str3 = this.f;
        if (str3 != null) {
            jsonGenerator.writeStringField("field3", str3);
        }
        String str4 = this.g;
        if ((str4 == null || str4.equals("")) && (this.e != null || this.f != null)) {
            str4 = k;
        }
        if (str4 != null) {
            jsonGenerator.writeStringField("fieldDelimiter", str4);
        }
        if (this.h != null) {
            jsonGenerator.writeFieldName("defaultSymbol");
            jsonGenerator.writeRawValue(this.h.toJson());
        }
        String str5 = this.i;
        if (str5 != null) {
            jsonGenerator.writeStringField("defaultLabel", str5);
        }
        jsonGenerator.writeFieldName("uniqueValueInfos");
        jsonGenerator.writeStartArray();
        boolean z = true;
        for (UniqueValue uniqueValue : this.j) {
            if (z) {
                z = false;
            } else {
                jsonGenerator.writeRaw(k);
            }
            jsonGenerator.writeRaw(uniqueValue.toJson(str4));
        }
        jsonGenerator.writeEndArray();
    }
}
